﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Babel.ParserGenerator;

namespace dragonangel.phpProject.Language.DSL
{
    public class CodeStatement : CodeExpression
    {
        internal CodeStatement() { }

        public CodeStatement(LexLocation begin, LexLocation end) : base(begin, end) { }
    }

    public class CodeStatementCollection : CodeStatement, IList<CodeStatement>
    {
        public CodeStatementCollection() : base() { }

        private IList<CodeStatement> statements = new List<CodeStatement>();

        public override LexLocation Begin
        {
            get
            {
                if (statements.Count > 0)
                    return statements[0].Begin;
                return new LexLocation();
            }
            set
            {
                throw new NotSupportedException();
            }
        }

        public override LexLocation End
        {
            get
            {
                if (statements.Count > 0)
                    return statements[statements.Count - 1].End;
                return new LexLocation();
            }
            set
            {
                throw new NotSupportedException();
            }
        }


        #region IList<CodeStatement> Members

        public int IndexOf(CodeStatement item)
        {
            return statements.IndexOf(item);
        }

        public void Insert(int index, CodeStatement item)
        {
            statements.Insert(index, item);
        }

        public void RemoveAt(int index)
        {
            statements.RemoveAt(index);
        }

        public CodeStatement this[int index]
        {
            get
            {
                return statements[index];
            }
            set
            {
                statements[index] = value;
            }
        }

        #endregion

        #region ICollection<CodeStatement> Members

        public void Add(CodeStatement item)
        {
            statements.Add(item);
        }

        public void Clear()
        {
            statements.Clear();
        }

        public bool Contains(CodeStatement item)
        {
            return statements.Contains(item);
        }

        public void CopyTo(CodeStatement[] array, int arrayIndex)
        {
            statements.CopyTo(array, arrayIndex);
        }

        public int Count
        {
            get { return statements.Count; }
        }

        public bool IsReadOnly
        {
            get { return statements.IsReadOnly; }
        }

        public bool Remove(CodeStatement item)
        {
            return statements.Remove(item);
        }

        #endregion

        #region IEnumerable<CodeStatement> Members

        public IEnumerator<CodeStatement> GetEnumerator()
        {
            return statements.GetEnumerator();
        }

        #endregion

        #region IEnumerable Members

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return ((System.Collections.IEnumerable)statements).GetEnumerator();
        }

        #endregion
    }
}
